package com.duowei.diandan.bean;

import android.os.Parcel;
import android.os.Parcelable;

import org.joda.time.LocalDateTime;

import java.util.Objects;

/**
 * 餐桌状态
 */
public class DeskStatus implements Parcelable {

    private String csbh;
    private LocalDateTime jcsj;
    private Float ys;
    private String zh;
    private String jcrs;
    private String wmdbh;
    private String by5;
    // private String by12;

    private String dcczYhbh;
    private String dcczYhmc;

    public DeskStatus() {
    }

    protected DeskStatus(Parcel in) {
        csbh = in.readString();
        if (in.readByte() == 0) {
            ys = null;
        } else {
            ys = in.readFloat();
        }
        zh = in.readString();
        jcrs = in.readString();
        wmdbh = in.readString();
        by5 = in.readString();
//        by12 = in.readString();
        dcczYhbh = in.readString();
        dcczYhmc = in.readString();
    }

    public static final Creator<DeskStatus> CREATOR = new Creator<DeskStatus>() {
        @Override
        public DeskStatus createFromParcel(Parcel in) {
            return new DeskStatus(in);
        }

        @Override
        public DeskStatus[] newArray(int size) {
            return new DeskStatus[size];
        }
    };

    public String getCsbh() {
        return csbh;
    }

    public void setCsbh(String csbh) {
        this.csbh = csbh;
    }

    public LocalDateTime getJcsj() {
        return jcsj;
    }

    public void setJcsj(LocalDateTime jcsj) {
        this.jcsj = jcsj;
    }

    public Float getYs() {
        return ys;
    }

    public void setYs(Float ys) {
        this.ys = ys;
    }

    public String getZh() {
        return zh;
    }

    public void setZh(String zh) {
        this.zh = zh;
    }

    public String getJcrs() {
        return jcrs;
    }

    public void setJcrs(String jcrs) {
        this.jcrs = jcrs;
    }

    public String getWmdbh() {
        return wmdbh;
    }

    public void setWmdbh(String wmdbh) {
        this.wmdbh = wmdbh;
    }

    public String getBy5() {
        return by5;
    }

    public void setBy5(String by5) {
        this.by5 = by5;
    }

//    public String getBy12() {
//        return by12;
//    }
//
//    public void setBy12(String by12) {
//        this.by12 = by12;
//    }

    public String getDcczYhbh() {
        return dcczYhbh;
    }

    public void setDcczYhbh(String dcczYhbh) {
        this.dcczYhbh = dcczYhbh;
    }

    public String getDcczYhmc() {
        return dcczYhmc;
    }

    public void setDcczYhmc(String dcczYhmc) {
        this.dcczYhmc = dcczYhmc;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof DeskStatus) {
            DeskStatus ds = (DeskStatus) obj;

            return Objects.equals(this.csbh, ds.csbh)
                    && Objects.equals(this.jcsj, ds.jcsj)
                    && Objects.equals(this.ys, ds.ys)
                    && Objects.equals(this.zh, ds.zh)
                    && Objects.equals(this.jcrs, ds.jcrs)
                    && Objects.equals(this.wmdbh, ds.wmdbh)
                    && Objects.equals(this.by5, ds.by5)
                    && Objects.equals(this.dcczYhbh, ds.dcczYhbh)
                    && Objects.equals(this.dcczYhmc, ds.dcczYhmc);

        } else {
            return false;
        }
    }

//    public static String querySql() {
//        return "SELECT a.csbh, b.jysj jcsj, b.ys, b.zh, b.jcrs, b.wmdbh, b.by5 " +
//                "FROM jycssz a, wmlsbjb b " +
//                "WHERE " +
//                "  (((charindex('@' + a.csmc + ',', '@' + b.zh) > 0) OR (charindex(',' + a.csmc + ',', b.zh) > 0)) AND b.sfyjz <> '1' AND " +
//                "   b.wmdbh IN (SELECT DISTINCT wmlsb.wmdbh " +
//                "               FROM wmlsb)) OR " +
//                "  (((charindex('@' + a.csmc + ',', '@' + b.zh) > 0) OR (charindex(',' + a.csmc + ',', b.zh) > 0)) AND " +
//                "   b.wmdbh IN (SELECT DISTINCT wmdbh " +
//                "               FROM JCZTB))|";
//    }

    public static String querySql() {
        return "SELECT x.csbh, x.jcsj, x.ys, x.zh, x.jcrs, x.wmdbh, x.by5, dccz.by1 as dcczYhbh, dccz.yhmc as dcczYhmc " +
                "FROM " +
                "  (SELECT a.csbh, b.jysj jcsj, b.ys, b.zh, b.jcrs, b.wmdbh, b.by5 " +
                "   FROM jycssz a, wmlsbjb b " +
                "   WHERE " +
                "     ((charindex('@' + a.csmc + ',', '@' + b.zh) > 0) OR (charindex(',' + a.csmc + ',', b.zh) > 0)) AND b.sfyjz <> '1' " +
                "     AND " +
                "     b.wmdbh IN (SELECT DISTINCT wmlsb.wmdbh " +
                "                 FROM wmlsb) " +
                "   UNION " +
                "   SELECT a.csbh, b.jysj jcsj, b.ys, b.zh, b.jcrs, b.wmdbh, b.by5 " +
                "   FROM jycssz a, wmlsbjb b " +
                "   WHERE ((charindex('@' + a.csmc + ',', '@' + b.zh) > 0) OR (charindex(',' + a.csmc + ',', b.zh) > 0)) AND " +
                "         b.wmdbh IN (SELECT DISTINCT wmdbh " +
                "                     FROM JCZTB)) x LEFT JOIN DCCZ ON X.CSBH = REPLACE(DCCZ.ZH, ',', '')|";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(csbh);
        if (ys == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeFloat(ys);
        }
        dest.writeString(zh);
        dest.writeString(jcrs);
        dest.writeString(wmdbh);
        dest.writeString(by5);
//        dest.writeString(by12);
        dest.writeString(dcczYhbh);
        dest.writeString(dcczYhmc);
    }
}
